<template>
  <view class="detail-box">
    <view class="detail-top">
      <view
        class="icon-text"
        :class="{
          'outer-bg-blue': iconBlue(detail.transType),
          'outer-bg-yellow': [2, 3].includes(detail.transType)
        }"
      >
        <view
          :class="{
            'inner-bg-blue': iconBlue(detail.transType),
            'inner-bg-yellow': [2, 3].includes(detail.transType)
          }"
        >
          {{ typeMap[detail.transType] }}
        </view>
      </view>
      <view class="title">{{ detail.supplierName }}</view>
      <view class="amount">{{ detail.revealAmount }}</view>
    </view>
    <view class="detail-bottom">
      <view>
        <view>交易类型</view>
        <view>{{ detail.transTypeText }}</view>
      </view>
      <view>
        <view>交易前余额</view>
        <view>{{ detail.frontTransAmount }}</view>
      </view>
      <view>
        <view>交易金额</view>
        <view>{{ detail.transAmount }}</view>
      </view>
      <view>
        <view>交易后余额</view>
        <view>{{ detail.backTransAmount }}</view>
      </view>
      <view>
        <view>交易时间</view>
        <view>{{ detail.createTime }}</view>
      </view>
      <view>
        <view>中转客户</view>
        <view>{{ detail.purchaserName }}</view>
      </view>
    </view>
  </view>
</template>
<script>
import { getDictDatas } from '@/api/transport.js';
import { getDetailById } from '@/api/wallet.js';
export default {
  data() {
    return {
      id: '',
      typeMap: {
        1: '充',
        2: '退',
        3: '货',
        4: '取'
      },
      detail: {},
      tradeTypeList: []
    };
  },
  computed: {
    iconBlue() {
      return (type) => {
        return (
          [1, 4].includes(type) &&
          this.$store.state.user.curTypeColor === '#409EFE'
        );
      };
    }
  },
  async onLoad(option) {
    this.id = option.id;
    await this.getDictDatas();
    this.getDetailByIdFn();
  },
  methods: {
    async getDictDatas() {
      const res = await getDictDatas();
      if (res.code === 0) {
        this.tradeTypeList = res?.data?.filter(
          (e) => e.dictType === 'trans_type'
        );
      }
    },
    async getDetailByIdFn() {
      const res = await getDetailById({ id: this.id });
      if (res.code === 0) {
        const result = res.data || {};
        result.transTypeText = this.tradeTypeList.find(
          (e) => e.value === result.transType.toString()
        )?.label;
        this.detail = result;
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.outer-bg-red {
  background-color: #ffa59c;
}
.inner-bg-red {
  background-color: #d32d2d;
}
.outer-bg-blue {
  background-color: #c5e2ff;
}
.inner-bg-blue {
  background-color: #49a4ff;
}
.outer-bg-yellow {
  background-color: #ffe8aa;
}
.inner-bg-yellow {
  background-color: #ffd155;
}
.detail-box {
  margin: 26.67rpx;
  padding: 35.56rpx 26.67rpx;
  background-color: #ffffff;
}
.icon-text {
  margin: auto;
  width: 117.33rpx;
  height: 117.33rpx;
  padding: 8rpx;
  color: #ffffff;
  border: 3.56rpx solid;
  border-radius: 60.44rpx;
  > view {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 53.33rpx;
    border-radius: 50%;
  }
}
.detail-top {
  text-align: center;
  border-bottom: 1px dotted #c2c2c2;
  .title {
    font-size: 32rpx;
    font-weight: 600;
    color: #333333;
    line-height: 50rpx;
    margin-top: 17.78rpx;
  }
  .amount {
    font-size: 56.89rpx;
    font-weight: 700;
    line-height: 60rpx;
    margin-bottom: 71.11rpx;
  }
}
.detail-bottom {
  font-size: 26.67rpx;
  padding-top: 53.33rpx;
  > view + view {
    margin-top: 17.78rpx;
  }
  > view {
    display: flex;
    justify-content: space-between;
    > view:first-child {
      color: #999999;
    }
  }
}
</style>
